<template>
  <div class="container">
      <van-form @submit="onSubmit">
          <div class="qiye-info">
              <div class="title">人才信息</div>
              <van-cell-group inset>
                  <van-field
                  v-model="form.name"
                  name="name"
                  label="姓名："
                  placeholder="请输入姓名"
                  required
                  :rules="[{ required: true, message: '请输入姓名' }]"
                  />
                  <van-field
                  v-model="sexValue"
                  is-link
                  readonly
                  label="性别："
                  placeholder="请选择性别"
                  @click="showPicker1 = true"
                  required
                  :rules="[{ required: true, message: '请选择性别' }]"
                />
                <van-popup v-model:show="showPicker1" round position="bottom">
                  <van-picker
                    :columns="sexList"
                    @cancel="showPicker1 = false"
                    @confirm="onConfirm1"
                  />
                </van-popup>

                <van-field
                  v-model="form.idCard"
                  name="idCard"
                  label="身份证号："
                  placeholder="请输入身份证号"
                  required
                  :rules="[{ required: true, message: '请输入身份证号' }]"
                  />

                  <van-field
                  v-model="nationValue"
                  is-link
                  readonly
                  label="民族："
                  placeholder="请选择民族"
                  @click="showPickerNation = true"
                  required
                  :rules="[{ required: true, message: '请选择民族' }]"
                />
                <van-popup v-model:show="showPickerNation" round position="bottom">
                  <van-picker
                    :columns="nationList"
                    @cancel="showPickerNation = false"
                    @confirm="onConfirmNation"
                  />
                </van-popup>

                  <van-field
                  v-model="form.phone"
                  name=""
                  label="联系电话："
                  placeholder="请输入联系电话"
                  required
                  :rules="[{ required: true, message: '请输入联系电话' }]"
                  />
                  <van-field
                  v-model="form.email"
                  name=""
                  label="电子邮箱："
                  placeholder="请输入电子邮箱"
                  required
                  :rules="[{ required: true, message: '请输入电子邮箱' }]"
                  />
                  <van-field
                  v-model="form.domicileAddress"
                  name="domicileAddress"
                  label="籍贯："
                  placeholder="请输入籍贯"
                  required
                  :rules="[{ required: true, message: '请输入籍贯' }]"
                  />
                  <van-field
                  v-model="form.residentialAddress"
                  name="residentialAddress"
                  label="居住地址："
                  placeholder="请输入居住地址"
                  required
                  :rules="[{ required: true, message: '请输入居住地址' }]"
                  />

                  <van-field
                  v-model="companyValue"
                  is-link
                  readonly
                  label="所属单位："
                  placeholder="请选择所属单位"
                  @click="showPickerCompany = true"
                  required
                  :rules="[{ required: true, message: '请选择所属单位' }]"
                />
                <van-popup v-model:show="showPickerCompany" round position="bottom">
                  <van-picker
                    :columns="companyList"
                    @cancel="showPickerCompany = false"
                    @confirm="onConfirmCompany"
                  />
                </van-popup>

                <van-field
                  v-model="levelValue"
                  is-link
                  readonly
                  label="人才等级："
                  placeholder="请选择人才等级"
                  @click="showPicker8 = true"
                  required
                  :rules="[{ required: true, message: '请选择人才等级' }]"
                />
                <van-popup v-model:show="showPicker8" round position="bottom">
                  <van-picker
                    :columns="levelList"
                    @cancel="showPicker8 = false"
                    @confirm="onConfirm8"
                  />
                </van-popup>
                  <van-field
                  v-model="form.occupation"
                  name="occupation"
                  label="现职务："
                  placeholder="请输入现职务"
                  required
                  :rules="[{ required: true, message: '请输入现职务' }]"
                  />

                  <van-field
                  v-model="zcValue"
                  is-link
                  readonly
                  label="职称："
                  placeholder="请选择职称"
                  @click="showPicker2 = true"
                  required
                  :rules="[{ required: true, message: '请选择职称' }]"
                />
                <van-popup v-model:show="showPicker2" round position="bottom">
                  <van-picker
                    :columns="zcList"
                    @cancel="showPicker2 = false"
                    @confirm="onConfirm2"
                  />
                </van-popup>

                <van-field
                  v-model="xlValue"
                  is-link
                  readonly
                  label="学历："
                  placeholder="请选择学历"
                  @click="showPicker3 = true"
                  required
                  :rules="[{ required: true, message: '请选择学历' }]"
                />
                <van-popup v-model:show="showPicker3" round position="bottom">
                  <van-picker
                    :columns="xlList"
                    @cancel="showPicker3 = false"
                    @confirm="onConfirm3"
                  />
                </van-popup>

                <van-field
                  v-model="xwValue"
                  is-link
                  readonly
                  label="学位："
                  placeholder="请选择学位"
                  @click="showPicker4 = true"
                  required
                  :rules="[{ required: true, message: '请选择学位' }]"
                />
                <van-popup v-model:show="showPicker4" round position="bottom">
                  <van-picker
                    :columns="xwList"
                    @cancel="showPicker4 = false"
                    @confirm="onConfirm4"
                  />
                </van-popup>

                <van-field
                  v-model="politicalValue"
                  is-link
                  readonly
                  label="政治面貌："
                  placeholder="请选择政治面貌"
                  @click="showPicker5 = true"
                  required
                  :rules="[{ required: true, message: '请选择政治面貌' }]"
                />
                <van-popup v-model:show="showPicker5" round position="bottom">
                  <van-picker
                    :columns="politicalList"
                    @cancel="showPicker5 = false"
                    @confirm="onConfirm5"
                  />
                </van-popup>

                <van-field
                  v-model="matrimonyValue"
                  is-link
                  readonly
                  label="婚姻状况："
                  placeholder="请选择婚姻状况"
                  @click="showPickerMatrimony = true"
                  required
                  :rules="[{ required: true, message: '请选择婚姻状况' }]"
                />
                <van-popup v-model:show="showPickerMatrimony" round position="bottom">
                  <van-picker
                    :columns="matrimonyList"
                    @cancel="showPickerMatrimony = false"
                    @confirm="onConfirmMatrimony"
                  />
                </van-popup>
                
                <van-field
                  v-model="form.contractStart"
                  name="contractStart"
                  label="合同签订时间："
                  placeholder="请选择合同签订时间"
                  readonly
                  required
                  :rules="[{ required: true, message: '请选择合同签订时间' }]"
                  @click="showStart = true"
                  />
                <van-calendar v-model:show="showStart" @confirm="onConfirmStart" switch-mode="year-month" />
                
                <van-field
                  v-model="form.contractEnd"
                  name="contractEnd"
                  label="合同到期时间："
                  placeholder="请选择合同到期时间"
                  readonly
                  required
                  :rules="[{ required: true, message: '请选择合同到期时间' }]"
                  @click="showEnd = true"
                  />
                <van-calendar v-model:show="showEnd" @confirm="onConfirmEnd" switch-mode="year-month" />
                
                <van-field
                  v-model="rdValue"
                  is-link
                  readonly
                  label="是否人大代表："
                  placeholder="请选择是否人大代表"
                  @click="showPicker6 = true"
                  required
                  :rules="[{ required: true, message: '请选择是否人大代表' }]"
                />
                <van-popup v-model:show="showPicker6" round position="bottom">
                  <van-picker
                    :columns="isRdList"
                    @cancel="showPicker6 = false"
                    @confirm="onConfirm6"
                  />
                </van-popup>

                <van-field
                  v-model="isZxValue"
                  is-link
                  readonly
                  label="是否政协委员："
                  placeholder="请选择是否政协委员"
                  @click="showPicker7 = true"
                  required
                  :rules="[{ required: true, message: '请选择是否政协委员' }]"
                />
                <van-popup v-model:show="showPicker7" round position="bottom">
                  <van-picker
                    :columns="isZxList"
                    @cancel="showPicker7 = false"
                    @confirm="onConfirm7"
                  />
                </van-popup>

                <van-field
                  v-model="isddbValue"
                  is-link
                  readonly
                  label="是否党代表："
                  placeholder="请选择是否党代表"
                  @click="showPickerddb = true"
                  required
                  :rules="[{ required: true, message: '请选择是否党代表' }]"
                />
                <van-popup v-model:show="showPickerddb" round position="bottom">
                  <van-picker
                    :columns="isZxList"
                    @cancel="showPickerddb = false"
                    @confirm="onConfirmDdb"
                  />
                </van-popup>

                <van-field
                  v-model="jobStatusValue"
                  is-link
                  readonly
                  label="在职状态："
                  placeholder="请选择在职状态"
                  @click="showPickerjobs = true"
                  required
                  :rules="[{ required: true, message: '请选择在职状态' }]"
                />
                <van-popup v-model:show="showPickerjobs" round position="bottom">
                  <van-picker
                    :columns="jobStatusList"
                    @cancel="showPickerjobs = false"
                    @confirm="onConfirmJobStatus"
                  />
                </van-popup>

                <van-field
                  is-link
                  readonly
                  label="人才来源地"
                  placeholder="请选择人才来源地"
                  @click="showRclyd = true"
                  v-model="fieldValue"
                  required
                  :field-names="fieldNames"
                  :rules="[{ required: true, message: '请选择人才来源地' }]"
                />
                <van-popup v-model:show="showRclyd" round position="bottom">
                  <van-cascader
                  v-model="code"
                  title="请选择所在地区: "
                  :options="originList"
                  :field-names="fieldNames"
                  @close="showRclyd = false"
                  @finish="onFinish"
                  />
                </van-popup>

                <van-field
                  v-model="rctxValue"
                  is-link
                  readonly
                  label="人才头衔："
                  placeholder="请选择人才头衔"
                  @click="showPickerRctx = true"
                  required
                  :rules="[{ required: true, message: '请选择人才头衔' }]"
                />
                <van-popup v-model:show="showPickerRctx" round position="bottom">
                  <van-picker
                    :columns="rctxList"
                    @cancel="showPickerRctx = false"
                    @confirm="onConfirmRctx"
                  />
                </van-popup>
              </van-cell-group>
          </div>
          <div class="qiye-info2">
            <div class="title">职位信息</div>
            <van-cell-group inset>
              <van-field
                v-model="form3.startJobDate"
                name="startJobDate"
                label="参加工作时间："
                placeholder="请选择参加工作时间"
                readonly
                required
                :rules="[{ required: true, message: '请选择参加工作时间' }]"
                @click="showStartJobDate = true"
                />
              <van-calendar v-model:show="showStartJobDate" @confirm="onConfirmStartJobDate" switch-mode="year-month" />
             
              <van-field
                v-model="form3.joinInDate"
                name="joinInDate"
                label="入职时间："
                placeholder="请选择入职时间"
                readonly
                required
                :rules="[{ required: true, message: '请选择入职时间' }]"
                @click="showjoinInDate = true"
                />
              <van-calendar v-model:show="showjoinInDate" @confirm="onConfirmjoinInDate" switch-mode="year-month" />
              
              <van-field
              v-model="form3.department"
              name="department"
              label="部门："
              placeholder="请输入部门"
              required
              :rules="[{ required: true, message: '请输入部门' }]"
              />
              <van-field
              v-model="form3.job"
              name="job"
              label="职务："
              placeholder="请输入职务"
              required
              :rules="[{ required: true, message: '请输入职务' }]"
              />
              <van-field
              v-model="form3.officePhone"
              name="officePhone"
              label="办公电话："
              placeholder="请输入办公电话"
              required
              :rules="[{ required: true, message: '请输入办公电话' }]"
              />

              <van-field
              v-model="jobNatureValue"
              is-link
              readonly
              label="职位性质："
              placeholder="请选择职位性质"
              @click="showPickerZwxz = true"
              required
              :rules="[{ required: true, message: '请选择职位性质' }]"
            />
            <van-popup v-model:show="showPickerZwxz" round position="bottom">
              <van-picker
                :columns="jobNatureList"
                @cancel="showPickerZwxz = false"
                @confirm="onConfirmjobNature"
              />
            </van-popup>

            <van-field
            v-model="offshoreValue"
            is-link
            readonly
            label="是否在离岸中心："
            placeholder="请选择是否在离岸中心"
            @click="showOffshore = true"
            required
            :rules="[{ required: true, message: '请选择是否在离岸中心' }]"
            />
            <van-popup v-model:show="showOffshore" round position="bottom">
              <van-picker
                :columns="isRdList"
                @cancel="showOffshore = false"
                @confirm="onConfirmOffshore"
              />
            </van-popup>
            <div class="title3">备注：</div>
            <van-field
            class="remark"
            type="textarea"
            :rows="3"
            v-model="form3.remark"
            name="remark"
            label=""
            placeholder=""
            />
            </van-cell-group>
          </div>

          <div class="qiye-info2">
            <div class="title">过往工作经历</div>
            <van-cell-group inset>
              <van-field
                v-model="form2.startDate"
                name="startDate"
                label="开始时间："
                placeholder="请选择开始时间"
                readonly
                required
                :rules="[{ required: true, message: '请选择开始时间' }]"
                @click="showStartDate = true"
                />
              <van-calendar v-model:show="showStartDate" @confirm="onConfirmStartDate" switch-mode="year-month" />
             
              <van-field
                v-model="form2.endDate"
                name="endDate"
                label="结束时间："
                placeholder="请选择结束时间"
                readonly
                required
                :rules="[{ required: true, message: '请选择结束时间' }]"
                @click="showEndDate = true"
                />
              <van-calendar v-model:show="showEndDate" @confirm="onConfirmEndDate" switch-mode="year-month" />
              <van-field
              v-model="form2.companyName"
              name="companyName"
              label="公司："
              placeholder="请输入公司名称"
              required
              :rules="[{ required: true, message: '请输入公司名称' }]"
              />
              <van-field
              v-model="form2.job"
              name="job"
              label="职务："
              placeholder="请输入职务"
              required
              :rules="[{ required: true, message: '请输入职务' }]"
              />
              <div class="title3">备注：</div>
              <van-field
              class="remark"
              type="textarea"
              :rows="3"
              v-model="form2.remark"
              name="remark"
              label=""
              placeholder=""
              />
            </van-cell-group>
          </div>
        <div class="addbtn">
          <van-button color='#1052CC' block type="primary" native-type="submit">
            确定
          </van-button>
        </div>
      </van-form>
  </div>
</template>

<script setup>
import { ref,reactive,onMounted,computed } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import { showToast } from 'vant';
import { getDictSelect, getOrigin,creatPositionInfo,creatTalentPerson,creatWorkHistory, getCompanyList } from '@/api/company';

const router = useRouter()
const route = useRoute();

const rctxList = [];
const getRctxList = () => {
getDictSelect('talent_person_head_title').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
        rctxList.push({
        text: item.fullName,
        value: item.enCode
      })
      console.log('rctxList:',rctxList);
    })
  }
})
}
const showPickerRctx = ref(false);
const rctxId = ref('')
const rctxValue = ref('')
const onConfirmRctx = ({ selectedOptions }) => {
  showPickerRctx.value = false;
  rctxValue.value = selectedOptions[0]?.text;
  rctxId.value = selectedOptions[0]?.value;
};


//选择民族
const nationList = [];
const getNationList = () => {
getDictSelect('Nation').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
        nationList.push({
          text: item.fullName,
          value: item.enCode
        })
      })
    }
  })
}
const showPickerNation = ref(false);
const nationId = ref('')
const nationValue = ref('')
const onConfirmNation = ({ selectedOptions }) => {
  showPickerNation.value = false;
  nationValue.value = selectedOptions[0]?.text;
  nationId.value = selectedOptions[0]?.value;
  console.log('nationId:',nationId.value);
};

const sexList = [];
const getSexList = () => {
getDictSelect('sex').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      sexList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker1 = ref(false);
const sexId = ref('')
const sexValue = ref('')
const onConfirm1 = ({ selectedOptions }) => {
  showPicker1.value = false;
  sexValue.value = selectedOptions[0]?.text;
  sexId.value = selectedOptions[0]?.value;
};

const page = ref({
  currentPage: 1,
  pageSize: 20,
});

const companyList = [];
const finished = ref(false);

//  下拉刷新
const reFetchData = () => {
  page.value.currentPage = 1;
  finished.value = false;
  companyList = []
  debounce(fetchData, 800)();
}

//  防抖
function debounce(func, delay) {
 let timeout
 return function () {
     const _this = this
     const args = [...arguments]
     if (timeout) {
         clearTimeout(timeout)
     }
     timeout = setTimeout(() => {
         func.apply(_this, args)
     }, delay)
 }
}


async function fetchData() {
if (finished.value) return;
const { code, data, msg } = await getCompanyList(page.value);
if (code == 200) {
  const { currentPage, pageSize, total } = data.pagination;
  // 判断是否到底
  if (currentPage * pageSize >= total) {
    finished.value = true;
  }
  // companyList.value = data.list;
  data.list.forEach(item=>{
    companyList.push({
        text: item.companyName,
        value: item.companyId
      })
    })

  //  准备加载新的数据
  page.value.currentPage++;
}else{
  showToast(msg)
}
}

const showPickerCompany = ref(false);
const companyId = ref('')
const companyValue = ref('')
const onConfirmCompany = ({ selectedOptions }) => {
  showPickerCompany.value = false;
  companyValue.value = selectedOptions[0]?.text;
  companyId.value = selectedOptions[0]?.value;
  console.log('companyValue.value:',companyValue.value);
  console.log('companyId.value:',companyId.value);
};

const zcList = [];
const getZcList = () => {
getDictSelect('talent_person_post_title').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      zcList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker2 = ref(false);
const zcId = ref('')
const zcValue = ref('')
const onConfirm2 = ({ selectedOptions }) => {
  showPicker2.value = false;
  zcValue.value = selectedOptions[0]?.text;
  zcId.value = selectedOptions[0]?.value;
};

const xlList = [];
const getXlList = () => {
getDictSelect('talent_person_edu').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      xlList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker3 = ref(false);
const xlId = ref('')
const xlValue = ref('')
const onConfirm3 = ({ selectedOptions }) => {
showPicker3.value = false;
xlValue.value = selectedOptions[0]?.text;
xlId.value = selectedOptions[0]?.value;
};

const xwList = [];
const getXwList = () => {
getDictSelect('talent_person_degree').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      xwList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker4 = ref(false);
const xwId = ref('')
const xwValue = ref('')
const onConfirm4 = ({ selectedOptions }) => {
showPicker4.value = false;
xwValue.value = selectedOptions[0]?.text;
xwId.value = selectedOptions[0]?.value;
};

const politicalList = [];
const getPoliticalListList = () => {
getDictSelect('talent_person_political').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      politicalList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker5 = ref(false);
const politicalId = ref('')
const politicalValue = ref('')
const onConfirm5 = ({ selectedOptions }) => {
showPicker5.value = false;
politicalValue.value = selectedOptions[0]?.text;
politicalId.value = selectedOptions[0]?.value;
};


const isRdList = [
{ text: '是', value: '1' },
{ text: '否', value: '0' },
];
const showPicker6 = ref(false);
const rdId = ref('')
const rdValue = ref('')
const onConfirm6 = ({ selectedOptions }) => {
showPicker6.value = false;
rdValue.value = selectedOptions[0]?.text;
rdId.value = selectedOptions[0]?.value;
};


const isZxList = [
  { text: '是', value: '1' },
  { text: '否', value: '0' },
  ];
  const showPicker7 = ref(false);
  const isZxId = ref('')
  const isZxValue = ref('')
  const onConfirm7 = ({ selectedOptions }) => {
    showPicker7.value = false;
    isZxValue.value = selectedOptions[0]?.text;
    isZxId.value = selectedOptions[0]?.value;
};

const showPickerddb = ref(false);
  const isddbId = ref('')
  const isddbValue = ref('')
  const onConfirmDdb = ({ selectedOptions }) => {
    showPickerddb.value = false;
    isddbValue.value = selectedOptions[0]?.text;
    isddbId.value = selectedOptions[0]?.value;
};

const jobStatusList = [];
const getJobStatusList = () => {
getDictSelect('talent_person_job_status').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
        jobStatusList.push({
          text: item.fullName,
          value: item.enCode
      })
    })
  }
})
}
const showPickerjobs = ref(false);
const jobStatusId = ref('')
const jobStatusValue = ref('')
const onConfirmJobStatus = ({ selectedOptions }) => {
  showPickerjobs.value = false;
  jobStatusValue.value = selectedOptions[0]?.text;
  jobStatusId.value = selectedOptions[0]?.value;
};



const levelList = [];
const getLevelList = () => {
getDictSelect('talent_person_level').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
      levelList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPicker8 = ref(false);
const levelId = ref('')
const levelValue = ref('')
const onConfirm8 = ({ selectedOptions }) => {
showPicker8.value = false;
levelValue.value = selectedOptions[0]?.text;
levelId.value = selectedOptions[0]?.value;
};

const matrimonyList = [];
const getMatrimonyList = () => {
getDictSelect('talent_person_matrimony').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
        matrimonyList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPickerMatrimony = ref(false);
const matrimonyId = ref('')
const matrimonyValue = ref('')
const onConfirmMatrimony = ({ selectedOptions }) => {
  showPickerMatrimony.value = false;
  matrimonyValue.value = selectedOptions[0]?.text;
  matrimonyId.value = selectedOptions[0]?.value;
  console.log('matrimonyId.value:',matrimonyId.value);
};

const date = ref('');
const showStart = ref(false);
const formatDate = (date) => `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
const onConfirmStart = (value) => {
  showStart.value = false;
  form.contractStart = formatDate(value);
};


const showEnd = ref(false);
const onConfirmEnd = (value) => {
showEnd.value = false;
form.contractEnd = formatDate(value);
};

const showStartDate = ref(false);
const onConfirmStartDate = (value) => {
showStartDate.value = false;
form2.startDate = formatDate(value);
};

const showEndDate = ref(false);
const onConfirmEndDate = (value) => {
showEndDate.value = false;
form2.endDate = formatDate(value);
};


//选择来源地
const showRclyd = ref(false);
const fieldValue = ref('');
const fieldId = ref('');
const code = ref('');
const provinceId = ref('');
const cityId = ref('');

var originList = [];
const getOriginList = () => {
getOrigin().then(res => {
  const {code,data} = res
  if(code === 200){
    originList = data
    console.log('originList:',originList);
  }
})
}
const fieldNames = {
text: 'fullName',
value: 'enCode'
};
const onFinish = ({ selectedOptions }) => {
showRclyd.value = false;
fieldValue.value = selectedOptions.map((option) => option.fullName).join('/');
fieldId.value = selectedOptions.map((option) => option.enCode).join('/');
console.log('fieldId:',fieldId.value);
provinceId.value = selectedOptions[0].enCode
cityId.value = selectedOptions[1].enCode
};

const form = reactive({
  name: '',
  idCard: '',
  residentialAddress: '',
  domicileAddress: '',
  occupation: '',
  contractStart: '',
  contractEnd: '',
  phone: '',
  email: ''
})
const form1Submit = () => {
let { name, idCard,phone,residentialAddress,domicileAddress,occupation,contractStart,contractEnd,email } = form;
const params = {
  companyId: companyId.value,
  name,
  idCard,
  sex: sexId.value,
  phone,
  email,
  residentialAddress,
  domicileAddress,
  occupation,
  contractStart,
  contractEnd,
  postTitle: zcId.value,
  eduBackground: xlId.value,
  eduDegree: xwId.value,
  political: politicalId.value,
  rd: rdId.value,
  zx: isZxId.value,
  province: provinceId.value,
  city: cityId.value,
  eduLevel: levelId.value,
  headTitle: rctxId.value,
  personId: route.query.personId,
  nation: nationId.value,
  matrimony: matrimonyId,
  partyPresent: isddbId.value,
  jobStatus: jobStatusId.value,
}
creatTalentPerson(params).then((res) => {
  console.log('creatTalentPerson:',res);
  const {code,data} = res
  if (code === 200) {
    console.log('人才信息创建成功');
    localStorage.setItem('personId', data.personInfo.personId)
    form3Submit()
    form2Submit()
  } else {
    showToast(res.msg)
  }
}).catch((err) => {
    console.log(err)
  })
}

const form2 = reactive({
  startDate: '',
  endDate: '',
  companyName: '',
  job: '',
  remark: '',
  historyId: '',
  personId: ''
})
const form2Submit = () =>{
let {startDate, endDate,companyName,job,historyId,remark,personId} = form2;
const params2 = {
  startDate,
  endDate,
  companyName,
  job,
  remark,
  historyId,
  personId
}
params2.personId = localStorage.getItem('personId')
creatWorkHistory(params2).then((res) => {
  if (res.code === 200) {
    console.log('工作经历创建成功');
    showToast(res.msg)
    router.push({ path: '/CompanyInfo', query: { status: '1' }});
  } else {
    showToast(res.msg)
  }
}).catch((err) => {
  console.log(err)
})
}

const showStartJobDate = ref(false);
const onConfirmStartJobDate = (value) => {
  showStartJobDate.value = false;
  form3.startJobDate = formatDate(value);
};

const showjoinInDate = ref(false);
const onConfirmjoinInDate = (value) => {
  showjoinInDate.value = false;
  form3.joinInDate = formatDate(value);
};

const jobNatureList = [];
const getjobNatureList = () => {
getDictSelect('talent_person_job_nature').then(res => {
  const {code,data} = res
  if(code === 200){
      data.forEach(item=>{
        jobNatureList.push({
        text: item.fullName,
        value: item.enCode
      })
    })
  }
})
}
const showPickerZwxz = ref(false);
const jobNatureId = ref('')
const jobNatureValue = ref('')
const onConfirmjobNature = ({ selectedOptions }) => {
  showPickerZwxz.value = false;
  jobNatureValue.value = selectedOptions[0]?.text;
  jobNatureId.value = selectedOptions[0]?.value;
};

const showOffshore = ref(false);
const offshoreId = ref('')
const offshoreValue = ref('')
const onConfirmOffshore = ({ selectedOptions }) => {
  showOffshore.value = false;
  offshoreValue.value = selectedOptions[0]?.text;
  offshoreId.value = selectedOptions[0]?.value;
};

const form3 = reactive({
  startJobDate: '',
  joinInDate: '',
  department: '',
  job: '',
  officePhone: '',
  remark: '',
})

const form3Submit = () =>{
let {startJobDate,joinInDate,department,job,officePhone,remark} = form3;
const params3 = {
  startJobDate,
  joinInDate,
  department,
  job,
  officePhone,
  jobNature: jobNatureId.value,
  offshore: offshoreId.value,
  remark,
}
params3.personId = localStorage.getItem('personId')
params3.companyId = companyId.value
creatPositionInfo(params3).then((res) => {
  if (res.code === 200) {
    console.log('职位信息创建成功');
    showToast(res.msg)
    router.push({ path: '/CompanyInfo', query: { status: '1' }});
  } else {
    showToast(res.msg)
  }
}).catch((err) => {
  console.log(err)
})
}

const onSubmit = (values) => {
  form1Submit()
  console.log("submit", values);
}

onMounted(() => {
  fetchData()
  getSexList()
  getZcList()
  getXlList()
  getXwList()
  getPoliticalListList()
  getLevelList()
  getOriginList()
  getRctxList()
  getjobNatureList()
  getNationList()
  getMatrimonyList()
  getJobStatusList()
})
</script>

<style lang="scss" scoped>
.container {
background: #f9f9f9;
overflow: hidden;
margin-bottom: 6.6rem;
padding: 0.9rem 1.3rem;
}
.navbar {
  position: fixed;
  top: 0;
  width: 100%;
  background-color: #fff;
}
.addbtn{
  position: fixed;
  bottom: 2rem;
  width: 92%;
  left: 4%;
}
.van-form{
  padding: 1.4rem 0 0 0;
}
.van-cell-group{
  background: #fff;
}
.van-field{
  border-bottom: 1px solid #E0E0E4;
  padding: 2rem 0 1.6rem;
}
.title{
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 1.5rem 1.2rem;
}
.qiye-info,.qiye-info2{
  background: #fff;
  padding-top: 1.2rem;
}
.qiye-info2{
  margin: 2rem 0;
  position: relative;
}
.dialog-qiye-info2{
  background: #fff;
  padding-top: 1.5rem;
}
.dialog-title{
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 0 1.2rem;
}
.qita{
  margin-top: 2rem;
  padding: 1.2rem;
  background: #fff;
  margin-bottom: 2.6rem;
}
.title2{
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 1.5rem 0;
}
.title3{
  font-size: 1.4rem;
  font-weight: 400;
  margin: 2rem 0 1.6rem 0;
}
.remark{
  border: 1px solid #E0E0E4;
  padding: 0.4rem 1rem!important;
  margin-bottom: 1.6rem;
}
::v-deep .van-field__label{
  width: 10rem!important;
}

.van-button{
  font-size: 1.8rem;
  font-weight: 400;
}
.van-cell{
  border-bottom: 1px solid #E0E0E4;
  padding: 2rem 0 1.6rem;
}
::v-deep .qiye-info .van-cell__title{
  width: 10rem !important;
  flex: none;
  margin-right: 1.2rem;
}
::v-deep .van-field__label {
  font-size: 1.3rem;
}

::v-deep .van-cell__title{
  width: 12rem !important;
  flex: none;
  margin-right: 1.2rem;
}
::v-deep .van-cell__value{
  text-align: left;
  color: #323233;
  font-size: 1.3rem;
}
.add{
  width: 16%;
  height: 2.6rem;
  line-height: 2.5rem;
  margin: 0 auto;
  text-align: center;
  font-size: 2.2rem;
  position: absolute;
  bottom: -2.6rem;
  background: #fff;
  left: 42%;
}
</style>